#ifndef _RANDOM_LEVEL_H
#define _RANDOM_LEVEL_H

#include <ctime>
 
template<unsigned MaxLevel, unsigned Probability>
class RandomLevel
{
public:
	static int randomLevel() 
	{
		if (!mInitialized)
		{
			mInitialized = true;
            srand(time(NULL));
		}
		int lvl = 1;
        //std::cout << frand() << std::endl;
		while (frand() < 1/float(Probability) && lvl < MaxLevel)
        {
			++lvl;
            //std::cout << frand() << std::endl;
        }
        return lvl;
	}
private:

	static bool mInitialized;

	static float inline frand() {
		return (float)((rand() % 100 + 1))/100;
	}
};

template<unsigned MaxLevel, unsigned Probability>
bool RandomLevel<MaxLevel, Probability>::mInitialized = false;
#endif /* _RANDOM_LEVEL_H */
